package com.sk.skplanet.commute.layouts;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Color;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ScrollView;
import android.widget.TextView;

import com.sk.skplanet.commute.R;
import com.sk.skplanet.commute.actions.Actions;
import com.sk.skplanet.commute.vo.Data;
import com.skp.Tmap.TMapView;

public class DialogLayout {

	/** 다이얼로그 버튼 레이아웃 */
	public static LinearLayout createDialogButtonLayout(Context context, Button button_dialog_summit,
			Button button_dialog_cancel) {
		LinearLayout layout_dialog_stopinfo = new LinearLayout(context);
		layout_dialog_stopinfo.setOrientation(LinearLayout.HORIZONTAL);
		layout_dialog_stopinfo.setBackgroundColor(Color.parseColor(Data.layout_pointColor));
		{
			LayoutParams layoutParams_layout_dialog_stopinfo = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
					LayoutParams.WRAP_CONTENT);
			layout_dialog_stopinfo.setLayoutParams(layoutParams_layout_dialog_stopinfo);
		}
		{// 확인버튼 설정 부분
			{
				android.view.ViewGroup.LayoutParams layoutParams_textview_dialogTitle = new LayoutParams(
						LayoutParams.MATCH_PARENT, Actions.DPFromPixel(60), 1);
				button_dialog_summit.setLayoutParams(layoutParams_textview_dialogTitle);
			}
			layout_dialog_stopinfo.addView(button_dialog_summit);

		}
		{// 취소버튼 설정 부분
			{
				android.view.ViewGroup.LayoutParams layoutParams_textview_dialogTitle = new LayoutParams(
						LayoutParams.MATCH_PARENT, Actions.DPFromPixel(60), 1);
				button_dialog_cancel.setLayoutParams(layoutParams_textview_dialogTitle);
			}
			layout_dialog_stopinfo.addView(button_dialog_cancel);
		}

		return layout_dialog_stopinfo;

	}

	/** 다이얼로그 전체 컨테이너 레이아웃 */
	public static LinearLayout createDialogLinearLayout(Context context) {
		LinearLayout layout_dialog_stopinfo = new LinearLayout(context);
		layout_dialog_stopinfo.setOrientation(LinearLayout.VERTICAL);

		layout_dialog_stopinfo.setMinimumWidth(Actions.PixelFromDP(1000));
		((View) layout_dialog_stopinfo).setMinimumHeight(android.R.dimen.dialog_min_width_minor);

		layout_dialog_stopinfo.setBackgroundColor(Color.parseColor(Data.layout_pointColor));
		{
			LayoutParams layoutParams_layout_dialog_stopinfo = new LinearLayout.LayoutParams(
					android.R.dimen.dialog_min_width_minor, LayoutParams.WRAP_CONTENT);
			// layoutParams_layout_dialog_stopinfo.setMargins(0, Actions.DPFromPixel(5), 0, Actions.DPFromPixel(5));
			layout_dialog_stopinfo.setLayoutParams(layoutParams_layout_dialog_stopinfo);
		}
		return layout_dialog_stopinfo;
	}

	/** 다이얼로그 타이틀 레이아웃 */
	public static LinearLayout createDialogTitleLayout(final Context context, int titleResourceId,
			final LinearLayout layout_dialog_stopinfo, final ScrollView scrollView, final TMapView TmapView) {
		final LinearLayout layout_dialog_title = new LinearLayout(context);
		layout_dialog_title.setTag(Data.DIALOG_MAP);
		layout_dialog_title.setOrientation(LinearLayout.HORIZONTAL);
		layout_dialog_title.setPadding(Actions.DPFromPixel(10), Actions.DPFromPixel(10), Actions.DPFromPixel(10),
				Actions.DPFromPixel(10));
		layout_dialog_title.setBackgroundColor(Color.parseColor(Data.layout_dialogTitle));
		{
			LinearLayout.LayoutParams layoutParams_layout_station = new LinearLayout.LayoutParams(
					LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
			layout_dialog_title.setLayoutParams(layoutParams_layout_station);
		}
		{// 정류장이름 텍스트뷰 설정 부분
			TextView textview_dialogTitle = new TextView(context);
			textview_dialogTitle.setText(titleResourceId);
			textview_dialogTitle.setTextColor(Color.parseColor(Data.textview_dialogTitle));
			textview_dialogTitle.setTextSize((float) Actions.DPFromPixel(14));
			{
				android.view.ViewGroup.LayoutParams layoutParams_textview_dialogTitle = new LayoutParams(
						LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0);
				textview_dialogTitle.setLayoutParams(layoutParams_textview_dialogTitle);
			}
			layout_dialog_title.addView(textview_dialogTitle);
		}

		{
			View view = new View(context);
			{
				android.view.ViewGroup.LayoutParams layoutParams_textview_dialogTitle = new LayoutParams(
						LayoutParams.MATCH_PARENT, 10, 1);
				view.setLayoutParams(layoutParams_textview_dialogTitle);
			}
			layout_dialog_title.addView(view);
		}

		if (titleResourceId == R.string.textview_dialog_station_title) {// 맵, 리스트 전환 버튼 설정 부분
			Button button_dialogTitle = new Button(context);
			if (layout_dialog_title.getTag() == Data.DIALOG_LIST) button_dialogTitle
					.setBackgroundResource(android.R.drawable.ic_dialog_map);
			else if (layout_dialog_title.getTag() == Data.DIALOG_MAP) button_dialogTitle
					.setBackgroundResource(android.R.drawable.ic_dialog_dialer);
			button_dialogTitle.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					if (layout_dialog_title.getTag() == Data.DIALOG_LIST) {
						layout_dialog_title.setTag(Data.DIALOG_MAP);
						v.setBackgroundResource(android.R.drawable.ic_dialog_dialer);
						layout_dialog_stopinfo.removeViewAt(layout_dialog_stopinfo.getChildCount() - 1);
						layout_dialog_stopinfo.addView(TmapView);

					} else if (layout_dialog_title.getTag() == Data.DIALOG_MAP) {
						layout_dialog_title.setTag(Data.DIALOG_LIST);
						v.setBackgroundResource(android.R.drawable.ic_dialog_map);
						layout_dialog_stopinfo.removeViewAt(layout_dialog_stopinfo.getChildCount() - 1);
						layout_dialog_stopinfo.addView(scrollView);
					}

				}
			});
			{
				android.view.ViewGroup.LayoutParams layoutParams_textview_dialogTitle = new LayoutParams(
						LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0);
				button_dialogTitle.setLayoutParams(layoutParams_textview_dialogTitle);
			}
			layout_dialog_title.addView(button_dialogTitle);
		}
		return layout_dialog_title;
	}

	/** 다이얼로그 리스트 내부 뷰 레이아웃 */
	public static LinearLayout createDialogViewLayout(final Context context, final AlertDialog alertDialog,
			final Object object, final String mainStr, String subStr, int type) {
		LinearLayout layout_station = new LinearLayout(context);
		{
			LinearLayout.LayoutParams layoutParams_layout_station = new LinearLayout.LayoutParams(
					LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
			layoutParams_layout_station.setMargins(0, Actions.DPFromPixel(3), 0, Actions.DPFromPixel(3));
			layout_station.setPadding(Actions.DPFromPixel(10), Actions.DPFromPixel(10), Actions.DPFromPixel(10),
					Actions.DPFromPixel(10));
			layout_station.setLayoutParams(layoutParams_layout_station);
			layout_station.setBackgroundResource(R.drawable.category_menu_bg_nor);
			layout_station.setOnTouchListener(new OnTouchListener() { // 버튼 터치시 이벤트
						public boolean onTouch(View v, MotionEvent event) {
							if (event.getAction() == MotionEvent.ACTION_DOWN) {// 버튼을 누르고 있을 때
								v.setBackgroundResource(R.drawable.category_menu_bg_sel);
							}
							if (event.getAction() == MotionEvent.ACTION_MOVE) { // 버튼에서 손을 떼었을 때
								if (!v.isPressed() || !v.isSelected()) {
									v.setBackgroundResource(R.drawable.category_menu_bg_nor);
								}
							}
							return false;
						}
					});
		}

		{// 정류장이름 텍스트뷰 설정 부분
			TextView textview_stationNameKor = new TextView(context);
			textview_stationNameKor.setText(mainStr);
			textview_stationNameKor.setTextColor(Color.parseColor(Data.textview_routeColor));
			textview_stationNameKor.setTextSize((float) Actions.DPFromPixel(11));
			if (type == Data.DIALOG_BUS) textview_stationNameKor.setTextColor(Color.parseColor(Actions
					.setBusTypeColor(subStr)));

			android.view.ViewGroup.LayoutParams layoutParams_textview_stationNameKor = new LayoutParams(
					LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			textview_stationNameKor.setLayoutParams(layoutParams_textview_stationNameKor);
			layout_station.addView(textview_stationNameKor);
		}

		{// 정류장번호 텍스트뷰 설정 부분
			TextView textview_stationId = new TextView(context);
			if (type == Data.DIALOG_STATION) textview_stationId.setText(" (" + subStr + ")");
			else if (type == Data.DIALOG_BUS) textview_stationId.setText(" (" + Actions.setBusTypeStr(subStr) + ")");
			textview_stationId.setTextColor(Color.parseColor(Data.textview_routeColor));
			textview_stationId.setTextSize((float) Actions.DPFromPixel(12));
			android.view.ViewGroup.LayoutParams layoutParams_textview_stationId = new LayoutParams(
					LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
			textview_stationId.setLayoutParams(layoutParams_textview_stationId);
			layout_station.addView(textview_stationId);
		}
		return layout_station;
	}

	/** 다이얼로그 리스트 뷰 컨테이너 레이아웃 */
	public static LinearLayout createDialogListView(final Context context) {
		LinearLayout layout_dialog_station = new LinearLayout(context); // 리스트 레이아웃
		layout_dialog_station.setOrientation(LinearLayout.VERTICAL);

		LayoutParams layoutParams_layout_dialog_station = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
				LayoutParams.MATCH_PARENT);
		layoutParams_layout_dialog_station.setMargins(0, Actions.DPFromPixel(5), 0, Actions.DPFromPixel(5));
		layout_dialog_station.setPadding(Actions.DPFromPixel(10), Actions.DPFromPixel(10), Actions.DPFromPixel(10),
				Actions.DPFromPixel(10));
		layout_dialog_station.setLayoutParams(layoutParams_layout_dialog_station);
		layout_dialog_station.setBackgroundColor(Color.parseColor(Data.layout_pointColor));
		return layout_dialog_station;

	}
}
